import {  Component,_decorator } from "cc";
import Skill from "../../skills/Skill";
import BattleObj from "../battle/BattleObj";
const { ccclass, property } = _decorator;

@ccclass('Hero')
export class Hero extends BattleObj{

    level:number;//等级
    star:number;//星级
    //运行时属性

    skillIds:number[] = []
    //人物静态配置
    //人物属性静态配置
    //技能,一个普攻，一个主动技能，一个被动，一个羁绊技能
    skills:Skill[] = [];
    //buff

    public init(){
        //属性初始化，根据等级获取属性

        //技能初始化
        this.initSkills()
    }

    initSkills(){
        //根据英雄的等级，星级获取技能
        //初始化技能，被动技能添加事件等

    }


    public releaseSkill(){
        let canReleaseSkills = []
        //拿到技能
        for (let index = 0; index < this.skills.length; index++) {
            const element = this.skills[index];
            if(element.cd <= 0){
                canReleaseSkills.push(element)
            }
        }
        if(canReleaseSkills.length > 0){
            //按优先级排序
            canReleaseSkills.sort((a,b)=>{
                return a.cfg.priority - b.cfg.priority
            })
        }
        let nowRealeaseSkill = null;
        if(canReleaseSkills.length > 0){
            nowRealeaseSkill = canReleaseSkills[0]
        }
        if(nowRealeaseSkill == null){
            //做一些其他操作
        }
        if(nowRealeaseSkill == null){
            return
        }
        //判断能不能放：基本判断：cd,消耗，状态
        if(!this.canRelease(nowRealeaseSkill)){
            return
        }
        //找目标
        let targets = this.findTargets(nowRealeaseSkill)
        if(!this.canReleaseWithTagets(nowRealeaseSkill,targets)){
            return
        }
        //技能释放各个时间点发布事件
        for (let index = 0; index < targets.length; index++) {
            const element = targets[index];
            //发布事件技能释放前的事件

        }
        //释放技能：技能效果执行
        //技能结束：cd,消耗，状态

    }
    canReleaseWithTagets(nowRealeaseSkill: any, targets: any[]) {
        //判断这些目标是否符合要求，比如无目标时能否释放等
        return true
    }
    findTargets(nowRealeaseSkill: any) {
        //找目标
        return []
    }
    canRelease(nowRealeaseSkill: Skill) {
        //cd
        //消耗
        //状态:是否无敌，是否被控制
        //是否在技能范围内
        return true
    }
}